{% extends "CmsBundle::base.html.twig" %}

{% block pluginStyles %}
    <link rel="stylesheet" href="/assets/cms/css/chosen.min.css" />
    <link rel="stylesheet" href="/assets/cms/plugins/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/assets/cms/css/uploadify.css">
{% endblock %}

{% block pageContent %}
    <!-- PAGE CONTENT BEGINS -->
    <form class="form-horizontal" role="form" method="post" action="{{ path("yearnfar_cms_post_edit", {"page":page, "sort":sort}) }}">
        <div class="form-group">
            <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 文章标题： </label>
            <div class="col-sm-9">
                <input type="hidden" name="pid" value="{{ current.id }}">
                <input type="text" name="title" placeholder="输入标题" class="col-xs-10 col-sm-5" value="{{ current.title }}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label no-padding-right" for="form-field-1">文章类型：</label>
            <div class="col-sm-9">
                <select class="width-20 chosen-select" name="tid" id="form-field-select-3" data-placeholder="Choose a Country...">
                    <option value="">&nbsp;</option>
                    {% for item in term %}
                        {% if item.id==current.tid %}
                            <option value="{{ item.id }}" selected="selected">{{ item.name2 }}</option>
                        {%  else %}
                            <option value="{{ item.id }}">{{ item.name2 }}</option>
                        {% endif %}
                    {% endfor %}
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label no-padding-right" for="form-field-1">公众号：</label>
            <div class="col-sm-9">
                <select class="width-20 chosen-select" name="aid" id="form-field-select-3" data-placeholder="Choose a Country...">
                    <option value="">&nbsp;</option>
                    {% for item in app %}
                        {% if item.id==current.aid %}
                            <option value="{{ item.id }}" selected="selected">{{ item.name }}</option>
                        {%  else %}
                            <option value="{{ item.id }}">{{ item.name }}</option>
                        {% endif %}
                    {% endfor %}
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 是否发布： </label>
            <div class="col-sm-9">
                <label>
                    <input type="checkbox" name="publish" class="ace" value="1" {% if current.publish %} checked="checked" {% endif %} />
                    <span class="lbl"></span>
                </label>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 封面地址： </label>
            <div class="col-sm-9">
                <!--<input type="file" id="id-input-file" name="cover" />-->
                <input type="text" id="cover" class="col-xs-10 col-sm-5" name="cover" value="{{ current.cover }}" />

                <div style="clear: both;padding: 10px 0 0 0;">
                    <span class="btn btn-sm">
                        <i class="ace-icon fa fa-cloud-upload align-top bigger-125"></i>
                        上传图片
                    </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span id="cover-del" class="btn btn-sm">
                        <i class="ace-icon fa fa-trash align-top bigger-125"></i>
                        删除图片
                    </span>
                    <input type="file" id="id-input-file" />
                </div>

            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label no-padding-right" for="form-field-1">内容：</label>
            <div class="col-sm-9">
                <textarea name="content" style="width:800px;height:400px;visibility:hidden;">{{ current.content }}</textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right"></label>
            <button class="btn btn-info" type="submit" name="submit" value="1">
                <i class="ace-icon fa fa-ok bigger-110"></i>
                提交
            </button>
            &nbsp; &nbsp; &nbsp;
            <button class="btn" type="reset">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                重置
            </button>
        </div>
    </form>
    <!-- PAGE CONTENT ENDS -->
{% endblock %}

{% block pluginScripts %}
    <script src="/assets/cms/js/chosen.jquery.min.js"></script>
    <script src="/assets/cms/plugins/kindeditor/kindeditor-min.js"></script>
    <script src="/assets/cms/plugins/kindeditor/lang/zh_CN.js"></script>
    <script src="/assets/cms/js/jquery.uploadify.min.js"></script>
{% endblock %}

{% block inlineScripts %}
    <script type="text/javascript">
        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="content"]', {
                uploadJson : "{{ path("yearnfar_cms_file_upload", {"name":"kindEditor"}) }}",
                allowFileManager : true
            });
        });

        jQuery(function($) {
            $(".chosen-select").chosen();

            setTimeout(function() {
                $('#id-input-file').uploadify({
                    'formData': {
                        'timestamp': '{{ timestamp }}',
                        'token': '{{ token }}'
                    },
                    width: 106,
                    height: 38,
                    'buttonText':'',
                    'swf': '/assets/cms/swf/uploadify.swf',
                    'uploader': '{{ path('yearnfar_cms_file_upload', {"name":"cover"}) }}',
                    'onUploadSuccess': function (file, data, respone) {
                        var obj = JSON.parse(data);
                        //
                        $('#cover').val(obj.data['link'][0]);
                    }
                });
            }, 100);

            $('#cover-del').on('click', function (){
                $('#cover').val('');
            })
        });

    </script>
{% endblock %}